/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.srcptit.trainning.thompv.BaitapMuc1_2;
import java.util.Scanner;
/**
 *
 * @author SONY
 */
public class Bai1Muc2 {
    public static void sapxep(int n,int a[])
    {
        for(int i=1;i<n;i++)
            for(int j=i+1;j<=n;j++)
                if(a[i]>a[j])
                {
                    int tmp=a[i];
                    a[i]=a[j];
                    a[j]=tmp;
                }
        System.out.println("Ket qua:");
       for(int i=1;i<=n;i++)
            System.out.print(a[i]+"   ");
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n,stop=1;
        String s;
        System.out.print("Nhap so luong phan tu: ");
        while(stop==1)
        {
            try
            {
                 s=sc.nextLine();
                 if(s.length()<1) throw new Exception("");
                 n=Integer.parseInt(s);
                 if(n<=0||n>1000) throw new Exception("");
                 stop=0;
                 int []a=new int[1000];
                 System.out.println("Nhap cac phan tu cua mang: ");
                 for(int i=1;i<=n;i++)
                    a[i]=sc.nextInt();
                 sapxep(n,a);
            }
            catch (Exception e)
            {
                System.out.println("Nhap lai: ");
            }
        }
    }
}
